const fs = require("fs");

const rs = fs.createReadStream("test.txt", {
  highWaterMark: 4,
});

const ws = fs.createWriteStream("test1.txt", {
  highWaterMark: 1,
});

let flag = true;

rs.on("data", (chunk) => {
  flag = ws.write(chunk, () => {
    console.log("ws执行完毕");
  });
  if (!flag) {
    rs.pause();
  }
});

ws.on("drain", () => {
  // 告之可读流可以进行生产数据
  rs.resume();
});
